using System.Text;
using UnityEngine;

public static class LogUtility
{
    public static void LogError(string message)
    {
        Debug.LogError(BuildString(message));
    }

    
    //  控制单线程内对字符串进行拼接操作
    private static readonly StringBuilder s_stringBuilder = new StringBuilder(1024 * 4);

    
    public static string BuildString(params string[] args)
    {
        return BuildString(false, args);
    }
    
    public static string BuildString(bool appendLine, params string[] args)
    {
        return BuildString(appendLine, (object[]) args);
    }
    
    public static string BuildString(params object[] args)
    {
        return BuildString(false, args);
    }

    
    /// <summary>
    /// 拼接字符串
    /// </summary>
    /// <param name="appendLine">拼接一次是否换行</param>
    /// <param name="args">待拼接字符串数组</param>
    /// <returns></returns>
    public static string BuildString(bool appendLine, params object[] args)
    {
        lock (s_stringBuilder)
        {
            s_stringBuilder.Length = 0;
            foreach (var arg in args)
            {
                s_stringBuilder.Append(arg);
                s_stringBuilder.Append(" ");
                if (appendLine)
                {
                    s_stringBuilder.AppendLine();
                }
            }
            return s_stringBuilder.ToString();
        }
    }
}